Option Explicit
'-----------Lay parameter
Dim args, folderPath, orginalText, destText
args = WScript.Arguments.Count

If args < 2 then
  WScript.Echo "Hay nhap doi so: [duong dan folder] [text can thay the->hdchonloc] "
  WScript.Quit
end If
folderPath = WScript.Arguments.Item(0) 
orginalText  = WScript.Arguments.Item(1) 
destText = "hdchonloc"

WScript.Echo "Ban da nhap doi so sau:" _
 & chr(34) & folderPath & Chr(34) _ 
 & ", " & chr(34) & orginalText & Chr(34)
 
 WScript.Echo "-------------------"
'-----------Thay doi test
Const ForReading = 1, ForWriting = 2, TristateTrue = -1
Dim fso,stream,strg,re
dim strComputer, objWMIService, FileList, objFile, errResult
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='"&folderPath&"'} Where " _
        & "ResultClass = CIM_DataFile")
For Each objFile In FileList	
    If objFile.Extension = "srt" Then		
		WScript.Echo "File thay doi: " & objFile.Drive & objFile.Path & _
			objFile.FileName & "." & objFile.Extension
		'Mo file
		Set fso = CreateObject("Scripting.FileSystemObject")
		Set stream =fso.OpenTextFile(objFile.Drive & objFile.Path & _
			objFile.FileName & "." & objFile.Extension,ForReading,False,TristateTrue)
		strg = stream.ReadAll()
		stream.Close
		Set stream = Nothing
		'Thay text
		Set re = New RegExp
		re.Global = True
		re.IgnoreCase = False
		re.Multiline = True
		re.Pattern = orginalText
		strg = re.Replace(strg,destText)
		'Ghi file
		Set stream =fso.OpenTextFile(objFile.Drive & objFile.Path & _
			objFile.FileName & "." & objFile.Extension,ForWriting,True,TristateTrue)
		stream.Write(strg)
		stream.Close
		Set stream = Nothing 
    End If
Next
WScript.Echo "-------------------"
WScript.Echo "Xu ly hoan tat."
WScript.Echo "Copyright vodacbao@gmail.com"


